<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/framework/tcp/ServerPool.cpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_5752cadd8276ecfd63d9b924f2a4d4b5.html">framework</a></li><li class="navelem"><a class="el" href="dir_c67741c6509c9bd4aec6faa9fd694608.html">tcp</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">ServerPool.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_server_pool_8cpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &quot;../../log/LogFactory.h&quot;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_service_8h.html">./framework/Service.h</a>&quot;</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_tcp_conf_8h.html">./config/TcpConf.h</a>&quot;</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_server_pool_8h.html">ServerPool.h</a>&quot;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_class_factory_8h.html">ClassFactory.h</a>&quot;</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160; </div>
<div class="line"><a name="l00010"></a><span class="lineno"><a class="line" href="class_server_pool.html#a12a50e25cde8c9244203f209515255b4">   10</a></span>&#160;<a class="code" href="class_server_pool.html#a12a50e25cde8c9244203f209515255b4">ServerPool::ServerPool</a>(<span class="keyword">const</span> <a class="code" href="class_tcp_config.html">TcpConfig</a>&amp; config) :<a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>(new std::vector&lt;<a class="code" href="class_shared_ptr.html">SharedPtr</a>&lt;<a class="code" href="class_service.html">Service</a>&gt; &gt;()), <a class="code" href="class_server_pool.html#ad224f2bdc4cfbdda3cd06291df8a84d1">_threads</a>(new std::vector&lt;<a class="code" href="class_shared_ptr.html">SharedPtr</a>&lt;<a class="code" href="class_c_thread.html">CThread</a>&gt; &gt;()), </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>(new <a class="code" href="class_tcp_config.html">TcpConfig</a>(config)), <a class="code" href="class_server_pool.html#a643ab334a61067204b501b508ae771c1">_curSize</a>(0)</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;{</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; config.<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>; i++)</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;    {</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;        <a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>-&gt;push_back(<a class="code" href="class_shared_ptr.html">SharedPtr&lt;Service&gt;</a>(config.<a class="code" href="class_tcp_config.html#a950bde20b77bfc007a96a9ca6e01a579">_serverFactory</a>-&gt;<a class="code" href="class_service_factory.html#ad325b9a50a3be97065877c4e4c2d3467">GetServer</a>(), <a class="code" href="struct_release_server.html">ReleaseServer</a>(config.<a class="code" href="class_tcp_config.html#a950bde20b77bfc007a96a9ca6e01a579">_serverFactory</a>.<a class="code" href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">Get</a>())));</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;        (*_servers)[i]-&gt;SetServiceFlag(std::string(1, (<span class="keywordtype">char</span>)i + <span class="charliteral">&#39;0&#39;</span>));</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;        <span class="keywordflow">if</span> (!(*<a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>)[i]-&gt;Init(*<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>)) exit(1);</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    }</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;}</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160; </div>
<div class="line"><a name="l00021"></a><span class="lineno"><a class="line" href="class_server_pool.html#a5e5d2d0784bdb5dd2bd485f0c757514f">   21</a></span>&#160;<a class="code" href="class_server_pool.html#a5e5d2d0784bdb5dd2bd485f0c757514f">ServerPool::~ServerPool</a>()</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;{</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    <span class="comment">// 先于服务类清空掉客户端</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>; ++i)</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    {</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        (*_servers)[i]-&gt;Clear();</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    }</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    <a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>-&gt;clear();</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <a class="code" href="class_server_pool.html#ad224f2bdc4cfbdda3cd06291df8a84d1">_threads</a>-&gt;clear();</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;}</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="class_server_pool.html#adc0967023cf8fc732222408e2ea30492">   32</a></span>&#160;<a class="code" href="tools_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a> <a class="code" href="class_server_pool.html#adc0967023cf8fc732222408e2ea30492">ServerPool::_Run</a>(<span class="keywordtype">void</span>* invoker)</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;{</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    <a class="code" href="class_service.html">Service</a>* s = (<a class="code" href="class_service.html">Service</a>*)invoker;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keywordflow">return</span> s-&gt;<a class="code" href="class_service.html#aad0c7b096b5dc39a0a763997f045c2d5">Run</a>() == <span class="keyword">true</span> ? 0 : 1;</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;}</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160; </div>
<div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="class_server_pool.html#affd0799fba666ca47cbcf4b08b203353">   38</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_server_pool.html#affd0799fba666ca47cbcf4b08b203353">ServerPool::PostConnect</a>(<span class="keywordtype">void</span>* invoker <span class="comment">/* = NullPtr */</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* addr <span class="comment">/* = NullPtr */</span>, <span class="keywordtype">int</span> port <span class="comment">/* = 0 */</span>)</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;{</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordflow">if</span> (<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a950bde20b77bfc007a96a9ca6e01a579">_serverFactory</a>-&gt;<a class="code" href="class_service_factory.html#ad325b9a50a3be97065877c4e4c2d3467">GetServer</a>()-&gt;<a class="code" href="class_service.html#a05c507629c3614ccbe433ea89fd0f985">IsServer</a>())</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    {</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>; i++)</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        {</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;            (*_servers)[i]-&gt;PostConnect(invoker);</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        }</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    }</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    {</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        <span class="keywordtype">size_t</span> pos = <a class="code" href="class_server_pool.html#a643ab334a61067204b501b508ae771c1">_curSize</a>++ % <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        (*_servers)[pos]-&gt;PostConnect(invoker, addr, port);</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    }</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;}</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160; </div>
<div class="line"><a name="l00054"></a><span class="lineno"><a class="line" href="class_server_pool.html#aa6b3d853618d2fccf4227e76962a6aa2">   54</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="class_server_pool.html#aa6b3d853618d2fccf4227e76962a6aa2">ServerPool::Run</a>()</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;{</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordflow">if</span> (<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a950bde20b77bfc007a96a9ca6e01a579">_serverFactory</a>.<a class="code" href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">Get</a>() == <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a> || <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a41473b0f5b097059e3e9b38df132928b">_clientFactory</a>.<a class="code" href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">Get</a>() == <a class="code" href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a>) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160; </div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <a class="code" href="_log_factory_8h.html#a3df9ded611daa86e2ddaa45c2bda32d7">LOG_SET_DIR</a>(<a class="code" href="_string_tools_8h.html#a0a60694576e1be5888918efa92f551d2">TO_TSTRING</a>(<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a41096d1aca56f5aebec1c3dbac38cc19">_logPath</a>).c_str());</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <a class="code" href="_log_factory_8h.html#a67aae99c7746aabb0b23348e0ee6c929">LOG_SET_FILE_SIZE</a>(<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a5851f2dfd954da7af02f8eff675a1084">_logSize</a>);</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <a class="code" href="_log_factory_8h.html#aa6e60c0db40fcf44166ed93a1fb15308">LOG_SET_SWITCH_FILE_TIME</a>(<a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a841d3925415410ccf5505fbb0b00a18a">_logTimeFlush</a>);</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    <a class="code" href="_log_factory_8h.html#a3bcb3081cc092adc9e13acb28e70d9e0">LOG_TOOLS</a>(<a class="code" href="logdef_8h.html#aca1fd1d8935433e6ba2e3918214e07f9abb2c17c44c343a8367060db4175f39ea">LOG_NORMAL</a>) &lt;&lt; <span class="stringliteral">&quot;Run start...&quot;</span>;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="comment">// 清空线程</span></div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <a class="code" href="class_server_pool.html#ad224f2bdc4cfbdda3cd06291df8a84d1">_threads</a>-&gt;clear();</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="comment">// run</span></div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>; i++)</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    {</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        <a class="code" href="class_server_pool.html#ad224f2bdc4cfbdda3cd06291df8a84d1">_threads</a>-&gt;push_back(<a class="code" href="class_shared_ptr.html">SharedPtr&lt;CThread&gt;</a>(<span class="keyword">new</span> <a class="code" href="class_c_thread.html">CThread</a>(&amp;<a class="code" href="class_server_pool.html#adc0967023cf8fc732222408e2ea30492">ServerPool::_Run</a>, (*<a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>)[i].Get())));</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    }</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160; </div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    <span class="comment">// join</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>; i++)</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    {</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        (*_threads)[i]-&gt;Join();</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    }</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160; </div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <a class="code" href="_log_factory_8h.html#a3bcb3081cc092adc9e13acb28e70d9e0">LOG_TOOLS</a>(<a class="code" href="logdef_8h.html#aca1fd1d8935433e6ba2e3918214e07f9abb2c17c44c343a8367060db4175f39ea">LOG_NORMAL</a>) &lt;&lt; <span class="stringliteral">&quot;Run end...&quot;</span>;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160; </div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;}</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160; </div>
<div class="line"><a name="l00082"></a><span class="lineno"><a class="line" href="class_server_pool.html#a30f1c48678e43f76c92788bcded61fbd">   82</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_server_pool.html#a30f1c48678e43f76c92788bcded61fbd">ServerPool::NotifyExit</a>()</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;{</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">_config</a>-&gt;<a class="code" href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">_serverSize</a>; i++)</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    {</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;        (*_servers)[i]-&gt;NotifyExit();</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    }</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;}</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160; </div>
<div class="line"><a name="l00090"></a><span class="lineno"><a class="line" href="class_server_pool.html#ae3e8550bb26038e7f655a8dafb1f4fee">   90</a></span>&#160;<span class="keywordtype">size_t</span> <a class="code" href="class_server_pool.html#ae3e8550bb26038e7f655a8dafb1f4fee">ServerPool::GetClientTotleSize</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="keyword"></span>{</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    <span class="keywordtype">size_t</span> size = 0;</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>-&gt;size(); i++)</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    {</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        size += (*_servers)[i]-&gt;GetSize();</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    }</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160; </div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;    <span class="keywordflow">return</span> size;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;}</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="class_server_pool.html#aeef9378764fa316c260dea2be56efc42">  101</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="class_server_pool.html#aeef9378764fa316c260dea2be56efc42">ServerPool::Post</a>(<span class="keyword">const</span> std::string&amp; clientIden, <a class="code" href="tools_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a>(*complete)(<span class="keywordtype">void</span>*), <span class="keywordtype">void</span>* invoker)</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;{</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    <span class="keywordflow">if</span> (clientIden.empty()) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160; </div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; <a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>-&gt;size(); ++i)</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    {</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        <span class="keywordflow">if</span> ((*<a class="code" href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">_servers</a>)[i]-&gt;IsServiceFlag(clientIden))</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;        {</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;            (*_servers)[i]-&gt;Post(complete, invoker);</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        }</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    }</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;    </div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;}</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160; </div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="a_log_factory_8h_html_a3df9ded611daa86e2ddaa45c2bda32d7"><div class="ttname"><a href="_log_factory_8h.html#a3df9ded611daa86e2ddaa45c2bda32d7">LOG_SET_DIR</a></div><div class="ttdeci">#define LOG_SET_DIR(dir)</div><div class="ttdoc">设置目录</div><div class="ttdef"><b>Definition:</b> <a href="_log_factory_8h_source.html#l00015">LogFactory.h:15</a></div></div>
<div class="ttc" id="aclass_tcp_config_html_a41473b0f5b097059e3e9b38df132928b"><div class="ttname"><a href="class_tcp_config.html#a41473b0f5b097059e3e9b38df132928b">TcpConfig::_clientFactory</a></div><div class="ttdeci">SharedPtr&lt; ClientFactory &gt; _clientFactory</div><div class="ttdoc">客户端类工厂</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00044">TcpConf.h:44</a></div></div>
<div class="ttc" id="aclass_service_html_aad0c7b096b5dc39a0a763997f045c2d5"><div class="ttname"><a href="class_service.html#aad0c7b096b5dc39a0a763997f045c2d5">Service::Run</a></div><div class="ttdeci">virtual bool Run()=0</div></div>
<div class="ttc" id="aclass_server_pool_html_ae8c968b775488ccc5f7e9a2babfb3938"><div class="ttname"><a href="class_server_pool.html#ae8c968b775488ccc5f7e9a2babfb3938">ServerPool::_servers</a></div><div class="ttdeci">SharedPtr&lt; std::vector&lt; SharedPtr&lt; Service &gt; &gt; &gt; _servers</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8h_source.html#l00056">ServerPool.h:56</a></div></div>
<div class="ttc" id="aclass_server_pool_html_ad224f2bdc4cfbdda3cd06291df8a84d1"><div class="ttname"><a href="class_server_pool.html#ad224f2bdc4cfbdda3cd06291df8a84d1">ServerPool::_threads</a></div><div class="ttdeci">SharedPtr&lt; std::vector&lt; SharedPtr&lt; CThread &gt; &gt; &gt; _threads</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8h_source.html#l00057">ServerPool.h:57</a></div></div>
<div class="ttc" id="aclass_shared_ptr_html"><div class="ttname"><a href="class_shared_ptr.html">SharedPtr</a></div><div class="ttdoc">智能指针</div><div class="ttdef"><b>Definition:</b> <a href="_shared_ptr_8h_source.html#l00119">SharedPtr.h:119</a></div></div>
<div class="ttc" id="aclass_shared_ptr_html_a0f15d2d3d2834b0667791f3abfd9e0d7"><div class="ttname"><a href="class_shared_ptr.html#a0f15d2d3d2834b0667791f3abfd9e0d7">SharedPtr::Get</a></div><div class="ttdeci">Ty * Get()</div><div class="ttdef"><b>Definition:</b> <a href="_shared_ptr_8h_source.html#l00202">SharedPtr.h:202</a></div></div>
<div class="ttc" id="aclass_server_pool_html_ac72f2b038411f9b731f7f152e812ed3e"><div class="ttname"><a href="class_server_pool.html#ac72f2b038411f9b731f7f152e812ed3e">ServerPool::_config</a></div><div class="ttdeci">SharedPtr&lt; TcpConfig &gt; _config</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8h_source.html#l00058">ServerPool.h:58</a></div></div>
<div class="ttc" id="aclass_server_pool_html_a30f1c48678e43f76c92788bcded61fbd"><div class="ttname"><a href="class_server_pool.html#a30f1c48678e43f76c92788bcded61fbd">ServerPool::NotifyExit</a></div><div class="ttdeci">void NotifyExit()</div><div class="ttdoc">通知服务退出</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00082">ServerPool.cpp:82</a></div></div>
<div class="ttc" id="aclass_server_pool_html_a643ab334a61067204b501b508ae771c1"><div class="ttname"><a href="class_server_pool.html#a643ab334a61067204b501b508ae771c1">ServerPool::_curSize</a></div><div class="ttdeci">size_t _curSize</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8h_source.html#l00059">ServerPool.h:59</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="aclass_tcp_config_html"><div class="ttname"><a href="class_tcp_config.html">TcpConfig</a></div><div class="ttdoc">客户端配置类</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00018">TcpConf.h:18</a></div></div>
<div class="ttc" id="a_server_pool_8h_html"><div class="ttname"><a href="_server_pool_8h.html">ServerPool.h</a></div></div>
<div class="ttc" id="astruct_release_server_html"><div class="ttname"><a href="struct_release_server.html">ReleaseServer</a></div><div class="ttdef"><b>Definition:</b> <a href="_class_factory_8h_source.html#l00068">ClassFactory.h:68</a></div></div>
<div class="ttc" id="aclass_server_pool_html_a5e5d2d0784bdb5dd2bd485f0c757514f"><div class="ttname"><a href="class_server_pool.html#a5e5d2d0784bdb5dd2bd485f0c757514f">ServerPool::~ServerPool</a></div><div class="ttdeci">~ServerPool()</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00021">ServerPool.cpp:21</a></div></div>
<div class="ttc" id="aclass_service_html"><div class="ttname"><a href="class_service.html">Service</a></div><div class="ttdoc">服务基类</div><div class="ttdef"><b>Definition:</b> <a href="_service_8h_source.html#l00019">Service.h:19</a></div></div>
<div class="ttc" id="aclass_server_pool_html_adc0967023cf8fc732222408e2ea30492"><div class="ttname"><a href="class_server_pool.html#adc0967023cf8fc732222408e2ea30492">ServerPool::_Run</a></div><div class="ttdeci">static DWORD _Run(void *invoker)</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00032">ServerPool.cpp:32</a></div></div>
<div class="ttc" id="aclass_service_factory_html_ad325b9a50a3be97065877c4e4c2d3467"><div class="ttname"><a href="class_service_factory.html#ad325b9a50a3be97065877c4e4c2d3467">ServiceFactory::GetServer</a></div><div class="ttdeci">virtual Service * GetServer()=0</div><div class="ttdoc">生产一个server,默认使用new Server</div></div>
<div class="ttc" id="alogdef_8h_html_aca1fd1d8935433e6ba2e3918214e07f9abb2c17c44c343a8367060db4175f39ea"><div class="ttname"><a href="logdef_8h.html#aca1fd1d8935433e6ba2e3918214e07f9abb2c17c44c343a8367060db4175f39ea">LOG_NORMAL</a></div><div class="ttdef"><b>Definition:</b> <a href="logdef_8h_source.html#l00013">logdef.h:13</a></div></div>
<div class="ttc" id="aclass_c_thread_html"><div class="ttname"><a href="class_c_thread.html">CThread</a></div><div class="ttdoc">线程类</div><div class="ttdef"><b>Definition:</b> <a href="_thread_8h_source.html#l00027">Thread.h:27</a></div></div>
<div class="ttc" id="a_class_factory_8h_html"><div class="ttname"><a href="_class_factory_8h.html">ClassFactory.h</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="a_log_factory_8h_html_a67aae99c7746aabb0b23348e0ee6c929"><div class="ttname"><a href="_log_factory_8h.html#a67aae99c7746aabb0b23348e0ee6c929">LOG_SET_FILE_SIZE</a></div><div class="ttdeci">#define LOG_SET_FILE_SIZE(fileSize)</div><div class="ttdoc">设置文件大小</div><div class="ttdef"><b>Definition:</b> <a href="_log_factory_8h_source.html#l00017">LogFactory.h:17</a></div></div>
<div class="ttc" id="a_log_factory_8h_html_aa6e60c0db40fcf44166ed93a1fb15308"><div class="ttname"><a href="_log_factory_8h.html#aa6e60c0db40fcf44166ed93a1fb15308">LOG_SET_SWITCH_FILE_TIME</a></div><div class="ttdeci">#define LOG_SET_SWITCH_FILE_TIME(switchFileTime)</div><div class="ttdoc">设置切换文件的时间(单位秒)</div><div class="ttdef"><b>Definition:</b> <a href="_log_factory_8h_source.html#l00019">LogFactory.h:19</a></div></div>
<div class="ttc" id="aclass_server_pool_html_a12a50e25cde8c9244203f209515255b4"><div class="ttname"><a href="class_server_pool.html#a12a50e25cde8c9244203f209515255b4">ServerPool::ServerPool</a></div><div class="ttdeci">ServerPool(const TcpConfig &amp;config)</div><div class="ttdoc">构造一个服务池</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00010">ServerPool.cpp:10</a></div></div>
<div class="ttc" id="aclass_server_pool_html_affd0799fba666ca47cbcf4b08b203353"><div class="ttname"><a href="class_server_pool.html#affd0799fba666ca47cbcf4b08b203353">ServerPool::PostConnect</a></div><div class="ttdeci">void PostConnect(void *invoker=NullPtr, const char *addr=NullPtr, int port=0)</div><div class="ttdoc">投递一个连接</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00038">ServerPool.cpp:38</a></div></div>
<div class="ttc" id="aclass_tcp_config_html_a950bde20b77bfc007a96a9ca6e01a579"><div class="ttname"><a href="class_tcp_config.html#a950bde20b77bfc007a96a9ca6e01a579">TcpConfig::_serverFactory</a></div><div class="ttdeci">SharedPtr&lt; ServiceFactory &gt; _serverFactory</div><div class="ttdoc">服务端类工厂</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00045">TcpConf.h:45</a></div></div>
<div class="ttc" id="aclass_server_pool_html_aeef9378764fa316c260dea2be56efc42"><div class="ttname"><a href="class_server_pool.html#aeef9378764fa316c260dea2be56efc42">ServerPool::Post</a></div><div class="ttdeci">bool Post(const std::string &amp;clientIden, DWORD(*complete)(void *), void *invoker)</div><div class="ttdoc">根据客户端标志，在相应的服务类中投递一个用户操作</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00101">ServerPool.cpp:101</a></div></div>
<div class="ttc" id="a_service_8h_html"><div class="ttname"><a href="_service_8h.html">Service.h</a></div></div>
<div class="ttc" id="a_string_tools_8h_html_a0a60694576e1be5888918efa92f551d2"><div class="ttname"><a href="_string_tools_8h.html#a0a60694576e1be5888918efa92f551d2">TO_TSTRING</a></div><div class="ttdeci">#define TO_TSTRING(str)</div><div class="ttdef"><b>Definition:</b> <a href="_string_tools_8h_source.html#l00079">StringTools.h:79</a></div></div>
<div class="ttc" id="a_tcp_conf_8h_html"><div class="ttname"><a href="_tcp_conf_8h.html">TcpConf.h</a></div></div>
<div class="ttc" id="aclass_server_pool_html_ae3e8550bb26038e7f655a8dafb1f4fee"><div class="ttname"><a href="class_server_pool.html#ae3e8550bb26038e7f655a8dafb1f4fee">ServerPool::GetClientTotleSize</a></div><div class="ttdeci">size_t GetClientTotleSize() const</div><div class="ttdoc">返回client总数量</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00090">ServerPool.cpp:90</a></div></div>
<div class="ttc" id="atools_8h_html_a798af1e30bc65f319c1a246cecf59e39"><div class="ttname"><a href="tools_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a></div><div class="ttdeci">unsigned int DWORD</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00134">tools.h:134</a></div></div>
<div class="ttc" id="aclass_service_html_a05c507629c3614ccbe433ea89fd0f985"><div class="ttname"><a href="class_service.html#a05c507629c3614ccbe433ea89fd0f985">Service::IsServer</a></div><div class="ttdeci">bool IsServer() const</div><div class="ttdoc">返回是否为服务端的标志</div><div class="ttdef"><b>Definition:</b> <a href="_service_8h_source.html#l00050">Service.h:50</a></div></div>
<div class="ttc" id="atools_8h_html_ab689500aaec0db066e3ac9483d3fe425"><div class="ttname"><a href="tools_8h.html#ab689500aaec0db066e3ac9483d3fe425">NullPtr</a></div><div class="ttdeci">#define NullPtr</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00119">tools.h:119</a></div></div>
<div class="ttc" id="aclass_tcp_config_html_a841d3925415410ccf5505fbb0b00a18a"><div class="ttname"><a href="class_tcp_config.html#a841d3925415410ccf5505fbb0b00a18a">TcpConfig::_logTimeFlush</a></div><div class="ttdeci">int _logTimeFlush</div><div class="ttdoc">切换日志文件的时间，单位，秒</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00043">TcpConf.h:43</a></div></div>
<div class="ttc" id="aclass_tcp_config_html_a5851f2dfd954da7af02f8eff675a1084"><div class="ttname"><a href="class_tcp_config.html#a5851f2dfd954da7af02f8eff675a1084">TcpConfig::_logSize</a></div><div class="ttdeci">int _logSize</div><div class="ttdoc">单个日志文件大小，单位Byte</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00042">TcpConf.h:42</a></div></div>
<div class="ttc" id="aclass_server_pool_html_aa6b3d853618d2fccf4227e76962a6aa2"><div class="ttname"><a href="class_server_pool.html#aa6b3d853618d2fccf4227e76962a6aa2">ServerPool::Run</a></div><div class="ttdeci">bool Run()</div><div class="ttdoc">启动服务</div><div class="ttdef"><b>Definition:</b> <a href="_server_pool_8cpp_source.html#l00054">ServerPool.cpp:54</a></div></div>
<div class="ttc" id="aclass_tcp_config_html_a274cd8dbfb340cb6b82f4e5f96c96182"><div class="ttname"><a href="class_tcp_config.html#a274cd8dbfb340cb6b82f4e5f96c96182">TcpConfig::_serverSize</a></div><div class="ttdeci">int _serverSize</div><div class="ttdoc">io服务个数</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00037">TcpConf.h:37</a></div></div>
<div class="ttc" id="aclass_tcp_config_html_a41096d1aca56f5aebec1c3dbac38cc19"><div class="ttname"><a href="class_tcp_config.html#a41096d1aca56f5aebec1c3dbac38cc19">TcpConfig::_logPath</a></div><div class="ttdeci">std::string _logPath</div><div class="ttdoc">日志目录</div><div class="ttdef"><b>Definition:</b> <a href="_tcp_conf_8h_source.html#l00041">TcpConf.h:41</a></div></div>
<div class="ttc" id="a_log_factory_8h_html_a3bcb3081cc092adc9e13acb28e70d9e0"><div class="ttname"><a href="_log_factory_8h.html#a3bcb3081cc092adc9e13acb28e70d9e0">LOG_TOOLS</a></div><div class="ttdeci">#define LOG_TOOLS(LEVEL)</div><div class="ttdoc">日志流操作宏工具</div><div class="ttdef"><b>Definition:</b> <a href="_log_factory_8h_source.html#l00013">LogFactory.h:13</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
